{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "19384578",
   "metadata": {},
   "source": [
    "----\n",
    "* 日期：2022-9-14\n",
    "* 课程：python\n",
    "* 记录人：杨静雯\n",
    "----\n",
    "# 回顾与复习\n",
    "\n",
    "> for+range()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b7c183c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e026d87b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建有序数值（创建常见自然数）\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "21d518b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,5)) # 产生了 5-0个值，默认从0开始    注：0（start）5（stop） 每一次增长1个单位(step)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7ab53db3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(2, 5)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(2,5)# 产生了5-2个值，start：2 syop:5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "64a7ad6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))  注：start不写 则默认为0，step不谢，则默认为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "01737adc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b3346cbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 7]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(1,10,3))    注：1（start）10（stop） 每一次增长3个单位(step)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff5ee561",
   "metadata": {},
   "source": [
    "### 实战：快速生成某个网站的所有页码的url队列\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "99db3896",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/xxyw/index.htm0.htm\n",
      "该次停留 2 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm1.htm\n",
      "该次停留 3 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm2.htm\n",
      "该次停留 3 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm3.htm\n",
      "该次停留 7 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm4.htm\n",
      "该次停留 10 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm5.htm\n",
      "该次停留 1 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm6.htm\n",
      "该次停留 2 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm7.htm\n",
      "该次停留 13 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm8.htm\n",
      "该次停留 9 秒\n",
      "https://www.nfu.edu.cn/xxyw/index.htm9.htm\n",
      "该次停留 10 秒\n"
     ]
    }
   ],
   "source": [
    "南方学院学校要闻=\"https://www.nfu.edu.cn/xxyw/index.htm\"\n",
    "页面后缀=\".htm\"\n",
    "page= 10\n",
    "\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻+str(i)+页面后缀) # 字符串拼接\n",
    "    random_num=random.randint(1,15)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "ce80ca88",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 总结，for+range  for可以执行循环，range决定了循环体的执行次数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac0b8d32",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "> 1. random随机模块\n",
    ">> 1. random.random()：生成0-1之间的 伪随机数（小数=浮点型数）（人是无办法创造随机数，所以人创造的机器也不可以创造出）\n",
    ">> 2. random.randint():生成a-b之间的随机整数 （整数）\n",
    ">> 3. random.choice():随机生成一个序列中的值（非空）\n",
    "> 2. time模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "974552d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 1.random\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "5977b64a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43.55574961156007"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()*100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "b1f347e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function random:\n",
      "\n",
      "random() method of random.Random instance\n",
      "    random() -> x in the interval [0, 1).\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "43bc260e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "## 2.randint\n",
    "help(random.randint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7a7350b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7c1ce772",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "2\n",
      "6\n",
      "1\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27e2bcdc",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 3.random.choice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c5224de",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(random.choice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "17224f13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'刘石珍'"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.choice(['刘石珍','杨静雯','刘慧琳'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7bac59f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7da75615",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sleep in module time:\n",
      "\n",
      "sleep(...)\n",
      "    sleep(seconds)\n",
      "    \n",
      "    Delay execution for a given number of seconds.  The argument may be\n",
      "    a floating point number for subsecond precision.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.sleep)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "b7e81e9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "time.sleep(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "6d368b8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hellllllo\n",
      "wowowowowowow\n"
     ]
    }
   ],
   "source": [
    "print(\"hellllllo\")\n",
    "time.sleep(5)\n",
    "print(\"wowowowowowow\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1152a21",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 3.课本实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d92c2775",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "import time,random\n",
    "\n",
    "odds=[1,3,5,7,9,11,1,15,17,19,21,23,25,27,29,31,35,37,39,41,43,45,47,49,51,53,57,59]\n",
    "\n",
    "# rigght_this_minute 是一个变量，是随着当前时间分钟数不断变化的一个值\n",
    "for i in range(5)\n",
    "right_this_second=datetime.datetime.today().second\n",
    "if right_this_second in odds:\n",
    "    print(right_this_secnd)\n",
    "    print(\"现在秒/时间为奇数\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "118d7b39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 bottles of beer on the wall.\n",
      "99 bottles beeeeeer.\n",
      "98 bottles of beer on the wall.\n",
      "98 bottles beeeeeer.\n",
      "97 bottles of beer on the wall.\n",
      "97 bottles beeeeeer.\n",
      "96 bottles of beer on the wall.\n",
      "96 bottles beeeeeer.\n",
      "95 bottles of beer on the wall.\n",
      "95 bottles beeeeeer.\n",
      "94 bottles of beer on the wall.\n",
      "94 bottles beeeeeer.\n",
      "93 bottles of beer on the wall.\n",
      "93 bottles beeeeeer.\n",
      "92 bottles of beer on the wall.\n",
      "92 bottles beeeeeer.\n",
      "91 bottles of beer on the wall.\n",
      "91 bottles beeeeeer.\n",
      "90 bottles of beer on the wall.\n",
      "90 bottles beeeeeer.\n",
      "89 bottles of beer on the wall.\n",
      "89 bottles beeeeeer.\n",
      "88 bottles of beer on the wall.\n",
      "88 bottles beeeeeer.\n",
      "87 bottles of beer on the wall.\n",
      "87 bottles beeeeeer.\n",
      "86 bottles of beer on the wall.\n",
      "86 bottles beeeeeer.\n",
      "85 bottles of beer on the wall.\n",
      "85 bottles beeeeeer.\n",
      "84 bottles of beer on the wall.\n",
      "84 bottles beeeeeer.\n",
      "83 bottles of beer on the wall.\n",
      "83 bottles beeeeeer.\n",
      "82 bottles of beer on the wall.\n",
      "82 bottles beeeeeer.\n",
      "81 bottles of beer on the wall.\n",
      "81 bottles beeeeeer.\n",
      "80 bottles of beer on the wall.\n",
      "80 bottles beeeeeer.\n",
      "79 bottles of beer on the wall.\n",
      "79 bottles beeeeeer.\n",
      "78 bottles of beer on the wall.\n",
      "78 bottles beeeeeer.\n",
      "77 bottles of beer on the wall.\n",
      "77 bottles beeeeeer.\n",
      "76 bottles of beer on the wall.\n",
      "76 bottles beeeeeer.\n",
      "75 bottles of beer on the wall.\n",
      "75 bottles beeeeeer.\n",
      "74 bottles of beer on the wall.\n",
      "74 bottles beeeeeer.\n",
      "73 bottles of beer on the wall.\n",
      "73 bottles beeeeeer.\n",
      "72 bottles of beer on the wall.\n",
      "72 bottles beeeeeer.\n",
      "71 bottles of beer on the wall.\n",
      "71 bottles beeeeeer.\n",
      "70 bottles of beer on the wall.\n",
      "70 bottles beeeeeer.\n",
      "69 bottles of beer on the wall.\n",
      "69 bottles beeeeeer.\n",
      "68 bottles of beer on the wall.\n",
      "68 bottles beeeeeer.\n",
      "67 bottles of beer on the wall.\n",
      "67 bottles beeeeeer.\n",
      "66 bottles of beer on the wall.\n",
      "66 bottles beeeeeer.\n",
      "65 bottles of beer on the wall.\n",
      "65 bottles beeeeeer.\n",
      "64 bottles of beer on the wall.\n",
      "64 bottles beeeeeer.\n",
      "63 bottles of beer on the wall.\n",
      "63 bottles beeeeeer.\n",
      "62 bottles of beer on the wall.\n",
      "62 bottles beeeeeer.\n",
      "61 bottles of beer on the wall.\n",
      "61 bottles beeeeeer.\n",
      "60 bottles of beer on the wall.\n",
      "60 bottles beeeeeer.\n",
      "59 bottles of beer on the wall.\n",
      "59 bottles beeeeeer.\n",
      "58 bottles of beer on the wall.\n",
      "58 bottles beeeeeer.\n",
      "57 bottles of beer on the wall.\n",
      "57 bottles beeeeeer.\n",
      "56 bottles of beer on the wall.\n",
      "56 bottles beeeeeer.\n",
      "55 bottles of beer on the wall.\n",
      "55 bottles beeeeeer.\n",
      "54 bottles of beer on the wall.\n",
      "54 bottles beeeeeer.\n",
      "53 bottles of beer on the wall.\n",
      "53 bottles beeeeeer.\n",
      "52 bottles of beer on the wall.\n",
      "52 bottles beeeeeer.\n",
      "51 bottles of beer on the wall.\n",
      "51 bottles beeeeeer.\n",
      "50 bottles of beer on the wall.\n",
      "50 bottles beeeeeer.\n",
      "49 bottles of beer on the wall.\n",
      "49 bottles beeeeeer.\n",
      "48 bottles of beer on the wall.\n",
      "48 bottles beeeeeer.\n",
      "47 bottles of beer on the wall.\n",
      "47 bottles beeeeeer.\n",
      "46 bottles of beer on the wall.\n",
      "46 bottles beeeeeer.\n",
      "45 bottles of beer on the wall.\n",
      "45 bottles beeeeeer.\n",
      "44 bottles of beer on the wall.\n",
      "44 bottles beeeeeer.\n",
      "43 bottles of beer on the wall.\n",
      "43 bottles beeeeeer.\n",
      "42 bottles of beer on the wall.\n",
      "42 bottles beeeeeer.\n",
      "41 bottles of beer on the wall.\n",
      "41 bottles beeeeeer.\n",
      "40 bottles of beer on the wall.\n",
      "40 bottles beeeeeer.\n",
      "39 bottles of beer on the wall.\n",
      "39 bottles beeeeeer.\n",
      "38 bottles of beer on the wall.\n",
      "38 bottles beeeeeer.\n",
      "37 bottles of beer on the wall.\n",
      "37 bottles beeeeeer.\n",
      "36 bottles of beer on the wall.\n",
      "36 bottles beeeeeer.\n",
      "35 bottles of beer on the wall.\n",
      "35 bottles beeeeeer.\n",
      "34 bottles of beer on the wall.\n",
      "34 bottles beeeeeer.\n",
      "33 bottles of beer on the wall.\n",
      "33 bottles beeeeeer.\n",
      "32 bottles of beer on the wall.\n",
      "32 bottles beeeeeer.\n",
      "31 bottles of beer on the wall.\n",
      "31 bottles beeeeeer.\n",
      "30 bottles of beer on the wall.\n",
      "30 bottles beeeeeer.\n",
      "29 bottles of beer on the wall.\n",
      "29 bottles beeeeeer.\n",
      "28 bottles of beer on the wall.\n",
      "28 bottles beeeeeer.\n",
      "27 bottles of beer on the wall.\n",
      "27 bottles beeeeeer.\n",
      "26 bottles of beer on the wall.\n",
      "26 bottles beeeeeer.\n",
      "25 bottles of beer on the wall.\n",
      "25 bottles beeeeeer.\n",
      "24 bottles of beer on the wall.\n",
      "24 bottles beeeeeer.\n",
      "23 bottles of beer on the wall.\n",
      "23 bottles beeeeeer.\n",
      "22 bottles of beer on the wall.\n",
      "22 bottles beeeeeer.\n",
      "21 bottles of beer on the wall.\n",
      "21 bottles beeeeeer.\n",
      "20 bottles of beer on the wall.\n",
      "20 bottles beeeeeer.\n",
      "19 bottles of beer on the wall.\n",
      "19 bottles beeeeeer.\n",
      "18 bottles of beer on the wall.\n",
      "18 bottles beeeeeer.\n",
      "17 bottles of beer on the wall.\n",
      "17 bottles beeeeeer.\n",
      "16 bottles of beer on the wall.\n",
      "16 bottles beeeeeer.\n",
      "15 bottles of beer on the wall.\n",
      "15 bottles beeeeeer.\n",
      "14 bottles of beer on the wall.\n",
      "14 bottles beeeeeer.\n",
      "13 bottles of beer on the wall.\n",
      "13 bottles beeeeeer.\n",
      "12 bottles of beer on the wall.\n",
      "12 bottles beeeeeer.\n",
      "11 bottles of beer on the wall.\n",
      "11 bottles beeeeeer.\n",
      "10 bottles of beer on the wall.\n",
      "10 bottles beeeeeer.\n",
      "9 bottles of beer on the wall.\n",
      "9 bottles beeeeeer.\n",
      "8 bottles of beer on the wall.\n",
      "8 bottles beeeeeer.\n",
      "7 bottles of beer on the wall.\n",
      "7 bottles beeeeeer.\n",
      "6 bottles of beer on the wall.\n",
      "6 bottles beeeeeer.\n",
      "5 bottles of beer on the wall.\n",
      "5 bottles beeeeeer.\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles beeeeeer.\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles beeeeeer.\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles beeeeeer.\n",
      "1 bottle of beer on the wall.\n",
      "1 bottle of beer on the wall.\n",
      "1 bottle beeeeeer.\n",
      "just only one,cant give you!!!\n"
     ]
    }
   ],
   "source": [
    "# 项目3 p44\n",
    "\n",
    "word=\"bottles\"\n",
    "\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num,word,\"of beer on the wall.\")\n",
    "    print(beer_num,word,\"beeeeeer.\")\n",
    "    if beer_num==1:\n",
    "        print(\"just only one,cant give you!!!\")\n",
    "    else:\n",
    "        new_num=beer_num-1\n",
    "        if new_num==1:\n",
    "            word=\"bottle\"\n",
    "            print(new_num,word,\"of beer on the wall.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9445bacc",
   "metadata": {},
   "source": [
    "## 课后任务；预习\n",
    "* 思考：什么是有序的数据（seq type)?\n",
    "* 预习：数值，字符串\n",
    "> 1. [Numeric Types]\n",
    "> 2. [Text Sequence Type]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aeb9be28",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c96c9818",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
